package ShunFeng;

import java.util.Scanner;

/**
 * Description：
 * Author: zhangc
 * Date：2017/9/20 16:02
 */
public class SHUZI {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i1 = scanner.nextInt();
        for (int i = 1; i < i1; i++) {
            if (getLucklyNumber(i) >= i1) {
                System.out.println((i - 1) % (int) (Math.pow(10, 9) + 7));
                return;
            }
        }
    }

    public static int getLucklyNumber(int N) {
        String str = Integer.toBinaryString(N);
        int level = str.length();
        if (!str.contains("0"))
            level += 1;
        int m = N - ((1 << (level - 1)) - 2);
        String result = Integer.toBinaryString(m - 1);
        while (result.length() < level - 1)
            result = "0" + result;
        result = result.replace("0", "4");
        result = result.replace("1", "7");
        return Integer.parseInt(result);
    }

}
